package com.sec.android.app.myfiles.feature;

import android.app.FragmentTransaction;
import android.content.Context;
import android.view.View;
import android.widget.AbsListView;

import com.altamirasoft.path_animation.PathLineAnimationView;
import com.sec.android.app.myfiles.feature.vi.ViEffectImp;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;

import java.util.ArrayList;

public class ViEffectMgr {
    private static ViEffectMgr sInstance = null;

    private ViEffectImp mViImp;

    public static ViEffectMgr getInstance() {
        if (sInstance == null) {
            sInstance = new ViEffectMgr();
        }

        return sInstance;
    }

    private ViEffectMgr() {
        mViImp = new ViEffectImp();
    }

    public void navigationEffect(NavigationInfo preInfo, NavigationInfo curInfo, FragmentTransaction ft) {
        if (mViImp != null) {
            if (preInfo != null) {
                boolean processed = false;
                FileRecord preRecord = preInfo.getCurRecord();
                FileRecord curRecord = curInfo.getCurRecord();
                if (preRecord != null && curRecord != null && (preRecord.getStorageType() == curRecord.getStorageType())) {
                    if (curRecord.getPath() != null && curRecord.getPath().equals(preRecord.getFullPath())) {
                        mViImp.enterFolder(ft);
                        processed = true;
                    } else if (preRecord.getPath() != null && preRecord.getPath().equals(curRecord.getFullPath())) {
                        mViImp.leaveFolder(ft);
                        processed = true;
                    }
                }

                if (!processed) {
                    mViImp.showFolder(ft);
                }
            }
        }
    }

    public void showCheckBox(Context context, View listView, View actionbar, boolean bShow) {
        if (mViImp != null) {
            mViImp.showCheckBox(context, listView, actionbar, bShow);
        }
    }

    public void fileSelectedBoxEffect(View mFileSelectedContainer, boolean bShow) {
        if (mViImp != null) {
            mViImp.fileSelectedBoxEffect(mFileSelectedContainer, bShow);
        }
    }

    public void setDeleteListItem(int processId, Context context, AbsListView twListView, ArrayList<Integer> itemList) {
        if (mViImp != null) {
            mViImp.setDeleteListItem(processId, context, twListView, itemList);
        }
    }

    public boolean doDeleteListItem(AbsMyFilesFragment fragment) {
        boolean bRet = false;
        if (mViImp != null) {
            bRet = mViImp.doDeleteListItem(fragment);
        }

        return bRet;
    }

    public void startBottomSheet(View view, int initialHeight) {
        if (mViImp != null) {
            mViImp.startBottomSheet(view, initialHeight);
        }
    }

    public void setEmptyViewAnimation(Context context, PathLineAnimationView pathView, View mainText, View subText, int rawId) {
        if (mViImp != null) {
            mViImp.setEmptyViewAnimation(context, pathView, mainText, subText, rawId);
        }
    }

    public void showBottomTextBox(View bottomMessageBox, boolean show) {
        if (mViImp != null) {
            mViImp.fileSelectedBoxEffect(bottomMessageBox, show);
        }
    }

    public void showGmsEmptyView(View emptyView) {
        if (mViImp != null) {
            mViImp.playGmsEmptyViewAnimation(emptyView);
        }
    }
}
